import Vue from 'vue'
import { Menu, Button, Card, Table, message } from 'ant-design-vue'
import VueRouter from 'vue-router'
import 'ant-design-vue/dist/antd.css'
// import actions from "@/shared/actions";
import SharedModule from "@/shared";

import './public-path'
import App from './App.vue'
import routes from './routes'

Vue.config.productionTip = false
Vue.use(Menu)
Vue.use(Button)
Vue.use(Card)
Vue.use(Table)
Vue.use(message)
Vue.use(VueRouter)

let instance = null;
let router = null;

function render(props = {}) {
  const { shared = SharedModule.getShared() } = props;
  SharedModule.overloadShared(shared);
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? '/sass' : '/',
    mode: 'history',
    routes,
  })
  instance = new Vue({
    router,
    render: (h) => h(App),
  }).$mount('#app')
}

if (!window.__POWERED_BY_QIANKUN__) {
  render()
}

export async function bootstrap() {
  console.log("VueMicroApp bootstrap");
}

export async function mount(props) {
  console.log("VueMicroApp mount", props);
  render(props)
}

export async function unmount() {
  console.log("VueMicroApp unmount");
  instance.$destroy()
  instance = null
  router = null
}
